import 'package:example_example/pages/tabs/WebOrder.dart';
import 'package:example_example/services/TLSizeFit.dart';
import 'package:example_example/util/LogUtil.dart';
import 'package:example_example/util/Storage.dart';
import 'package:example_example/util/ToastUtils.dart';
import 'package:flutter/material.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import '../pages/tabs/Order.dart';
import '../pages/tabs/Person.dart';
import '../pages/tabs/DynamicOrder.dart';
import '../pages/tabs/MyNeedDo.dart';

import '../YColors.dart';
import 'tabs/Home.dart';
import 'tabs/PersonCenter.dart';

class Tabs extends StatefulWidget {
  final index;

  Tabs({Key key, this.index = 0}) : super(key: key);

  _TabState createState() => _TabState(this.index);
}

class _TabState extends State<Tabs> {
  int _currentIndex;

  double imageWith = 30;
  double imageHeight = 35;

  _TabState(index) {
    this._currentIndex = index;
  }

  List _pageList = [
//    HomePage(),
//    OrderPage(),  // tab页形式的 写死的 我的待办
//    DynamicOrderPage(),  // tab页形式的 接口中获取数据的 我的待办
    MyNeedDoPage(),// 设计图的我的待办
    // WebOrderPage(),
//    PersonPage(),
    PersonCenter(),  // 个人中心

  ];
  
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    TLSizeFit.initialize();

    return Scaffold(
//      appBar: AppBar(
//        title: Text("Flutter Demo"),
//      ),
      body: this._pageList[_currentIndex],

      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex,
        //配置对应的索引值选中
        onTap: (int index) {
          print('//.....index:$index');
//          setJudgeIsLogin(index);
          setState(() {
            // 改变状态
            this._currentIndex = index;
          });
        },

//        iconSize: 30,   //icon的大小
        selectedFontSize: 13,
        // 字体的大小
        unselectedFontSize: 12,
//        fixedColor: Colors.green,  //选中的颜色
//        fixedColor: Color(0xff4CBC5A),  //选中的颜色
        fixedColor: YColors.l,
        //选中的颜色
        type: BottomNavigationBarType.fixed,
        //配置底部tabs可以有多个按钮

        items: [
//          BottomNavigationBarItem(
//              icon: Icon(Icons.home),
//              icon: Image.asset('images/marketdemand_off.png'),
//              activeIcon: Image.asset('images/marketdemand_on.png'),
//              title: Text("工单市场")),
////
//          BottomNavigationBarItem(
////              icon: Icon(Icons.home),
//              icon: Image.asset('images/marketdemand_off.png'),
//              activeIcon: Image.asset('images/marketdemand_on.png'),
//              title: Text("测试类")),

          BottomNavigationBarItem(
//              icon: Icon(Icons.category),
              icon: Image.asset('images/mydo_unselect.png',width: TLSizeFit.setPx(imageWith),height: TLSizeFit.setPx(imageWith),),
              activeIcon: Image.asset('images/mydo_selected.png',width: TLSizeFit.setPx(imageWith),height: TLSizeFit.setPx(imageWith)),
              title: Text("我的待办")),

          BottomNavigationBarItem(
//              icon: Icon(Icons.settings),
              icon: Image.asset('images/person_unselect.png',width: TLSizeFit.setPx(imageWith),height: TLSizeFit.setPx(imageWith)),
              activeIcon: Image.asset('images/person_selected.png',width: TLSizeFit.setPx(imageWith),height: TLSizeFit.setPx(imageWith)),
              title: Text("个人中心")
          ),
        ],
      ),
    );
  }

  // 判断是否登录
  setJudgeIsLogin(index) async {
//    var strStor = await Storage.getString(Global.LOGINDATA);
//    if (strStor == null || strStor == '') {
//      if (index == 1 || index == 3) {
//        Navigator.pushNamed(context, '/login');
//      } else {
//        setState(() {
//          // 改变状态
//          this._currentIndex = index;
//        });
//      }
//    } else {
//      setState(() {
//        // 改变状态
//        this._currentIndex = index;
//      });
//    }
  }

}
